<template>
  <div>
    <Spin :spinning="exportLoading" tip="Loading...">
      <FormPanel ref="from" :list="formList" @formChange="changeHandle" :isSubmitBtn="false" :collapse="false" labelWidth="110" />

      <div style="height: 57px"></div>
      <div
        :style="{
          position: 'absolute',
          left: 0,
          bottom: 0,
          right: 0,
          zIndex: 9,
          borderTop: '1px solid #e9e9e9',
          padding: '10px 20px',
          background: '#fff',
          textAlign: 'right',
        }"
      >
        <el-button @click="closeDrawer(1)">取 消</el-button>

        <multiuse-button type="primary" :click="closeDrawer.bind(this, 2)">确 定</multiuse-button>
      </div>
    </Spin>
  </div>
</template>
<script>
import { queryList, invalidApplyRed } from '@/api/omFinanceP/RebateManage/RebateInvoiceAudit';
export default {
  data() {
    this.saveData = null;
    return {
      formList: this.createdFrom(),
      exportLoading: false,
    };
  },
  components: {},
  props: ['list'],
  methods: {
    createdFrom() {
      return [
        {
          type: 'TEXT_AREA',
          label: '作废原因',
          fieldName: 'cancelReason',
          placeholder: '请输入',
          selfCols: 3,
          rules: [{ required: true, message: '请输入', trigger: 'blur' }],
        },
      ];
    },
    changeHandle(val) {
      this.saveData = val;
    },
    async closeDrawer(type) {
      if (type == 1) {
        this.$emit('close');
      } else {
        this.$refs.from.SUBMIT_FORM();
        if (this.saveData !== null) {
          this.exportLoading = true;
          let json = JSON.parse(JSON.stringify(this.saveData));
          let data = this.list;
          data.cancelReason = json.cancelReason;
          await this.$confirm('是否确认作废返利红票申请?', '提示', {
            confirmButtonText: '确认',
            cancelButtonText: '取消',
            type: 'warning',
          })
            .then(async () => {
              let res = await invalidApplyRed(data);
              if (res.resultCode === 200) {
                this.$notify({
                  title: '成功',
                  message: ' 作废操作成功',
                  type: 'success',
                });
                this.fetchParams = Object.assign({}, this.fetchParams);
              }
            })
            .catch(() => {});
          this.$emit('close', json);
        } else {
          this.exportLoading = false;
          this.saveData = null;
        }
      }
    },
  },
};
</script>
